
<!-- 隐私设置 -->
<template>
	<view class="page">
		<view class="card">
			<view class="item flex justify-between align-center">
				<view class="text">
					允许别人查看我的主页
				</view>
				<view class="button">
					<u-switch size="30" v-model="show1" @change="change1(item.homepageType,qureyA)"></u-switch>
				</view>
			</view>
			<view class="item flex justify-between align-center">
				<view class="text">
					允许别人查看我的粉丝
				</view>
				<view class="button">
					<u-switch size="30" v-model="show2" @change="change2(item.fanType,qureyB)"></u-switch>
				</view>
			</view>
			<view class="item flex justify-between align-center" >
				<view class="text">
					允许别人查看我的关注
				</view>
				<view class="button">
					<u-switch size="30" v-model="show3" @change="change3(item.attentionType,qureyC)"></u-switch>
				</view>
			</view>
			<view class="item flex justify-between align-center">
				<view class="text">
					允许陌生人查看我的动态
				</view>
				<view class="button">
					<u-switch size="30" v-model="show4" @change="change4(item.dynamicType,qureyD)"></u-switch>
				</view>
			</view>
		</view>	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				item:{},
				qureyA:{
					homepageType:Number,
				},
				qureyB:{
					fanType:Number,
				},
				qureyC:{
					attentionType:Number
				},
				qureyD:{
					dynamicType:Number
				},
				show1:Boolean,
				show2:Boolean,
				show3:Boolean,
				show4:Boolean
			}
		},
		onLoad() {
			this.getdata()
		},
		methods: {
			//修改隐私
			change1(t,e){
				console.log(t)
				if(t == 1){
					this.qureyA.homepageType = 0
				}else{
					this.qureyA.homepageType = 1
				}
				this.$post('/user/updateUserPrivacyList',e)
				this.getData()
			},
			change2(t,e){
				if(t == 1){
					this.qureyB.fanType = 0
				}else{
					this.qureyB.fanType = 1
				}
				this.$post('/user/updateUserPrivacyList',e)
				this.getData()
			},
			change3(t,e){
				if(t == 1){
					this.qureyC.attentionType = 0
				}else{
					this.qureyC.attentionType = 1
				}
				this.$post('/user/updateUserPrivacyList',e)
				this.getData()
			},
			change4(t,e){
				if(t == 1){
					this.qureyD.dynamicType = 0
				}else{
					this.qureyD.dynamicType = 1
				}
				this.$post('/user/updateUserPrivacyList',e)
				this.getData()
			},
			async getData(){
				let {data: item} = await this.$get('/user/userPrivacyList')
				console.log(item)
				this.item = item
			},
			//判断开关状态
			toBool() {
				if(this.item.homepageType == 0){
					this.show1 = false
				}else{
					this.show1 = true
				}
				if(this.item.fanType == 0){
					this.show2 = false
				}else{
					this.show2 = true
				}
				if(this.item.attentionType == 0){
					this.show3 = false
				}else{
					this.show3 = true
				}
				if(this.item.dynamicType == 0){
					this.show4 = false
				}else{
					this.show4 = true
				}
			},
			async getdata(){
				await this.getData()
				await this.toBool()
			}
			
		}
	}
</script>

<style lang="scss">
.page{
	padding: 30rpx;
	background: #f5f5f5;
	min-height: 100vh;
	.card{
		width: 690rpx;
		height: 480rpx;
		background: #FFFFFF;
		border-radius: 24rpx;
		padding: 0 30rpx;
		.item{
			height: 25%;
			.text{
				font-weight: 500;
				color: #333333;
				font-size: 32rpx;
			}
			.button{
				width: 60rpx;
				height: 31rpx;
			}
		}
	}
}
</style>
